﻿//
// eCRAM, a monthly activity report web application
// Copyright (C) 2010  Aptea
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

using System.Linq;
using System.Collections.Generic;

namespace eCRAM.Dao
{
    /// <summary>
    /// Implements the "repository" pattern, code factorization.
    /// </summary>
    ///
    /// <remarks>
    /// See http://dotnet.developpez.com/mvc/mvc-linq-to-sql/ (french) or
    /// http://www.asp.net/learn/mvc/tutorial-10-cs.aspx (english) for more informations
    /// about LINQ to SQL and the "repository" pattern.
    /// </remarks>
    ///
    /// <typeparam name="T">Cram, User...</typeparam>
    public interface IRepository<T>
    {
        /// <summary>
        /// Gets all the elements from the SQL table.
        /// </summary>
        /// <returns>all elements</returns>
        IQueryable<T> GetAll();

        /// <summary>
        /// Adds an element to the SQL table.
        /// </summary>
        /// <param name="t">element to add</param>
        void Create(T t);

        /// <summary>
        /// Updates the given element inside the SQL table.
        /// </summary>
        /// <param name="t">element to update</param>
        //void Update(T t);

        /// <summary>
        /// Deletes the given element inside the SQL table.
        /// </summary>
        /// <param name="t">element to delete</param>
        void Delete(T t);


        /// <summary>
        /// Gets the element by id from the SQL table.
        /// </summary>
        /// <returns>element</returns>
        T GetById(System.Guid id);

        /// <summary>
        /// Gets the elements count
        /// </summary>
        /// <returns>element</returns>
        int GetCount();

        /// <summary>
        /// Gets the element from the SQL table based on start and limit index
        /// </summary>
        /// <returns>element</returns>
        IQueryable<T> GetTop(int start, int limit);


        /// <summary>
        /// Commits the changes to the SQL table.
        /// </summary>
        void SubmitChanges();
    }
}
